//
//  WHYStatusRetweetedCell.swift
//  WHYWeibo-1.0
//
//  Created by 王洪运 on 15/11/27.
//  Copyright © 2015年 王洪运. All rights reserved.
//

import UIKit
import FFLabel

class WHYStatusRetweetedCell: WHYStatusCell {
    
    override var viewModel: WHYStatusViewModel? {
        didSet {
            let text = viewModel?.retweetedText ?? ""
            retweetedLabel.attributedText = WHYEmoticonManager.sharedManager.emoticonText(text, font: retweetedLabel.font)
            
            pictureView.snp_updateConstraints { (make) -> Void in
                let offset = viewModel?.thumbnailUrls == nil ? 0 : WHYStatusCellMagrin
                make.top.equalTo(retweetedLabel.snp_bottom).offset(offset)
            }
        }
    }

    private lazy var backButton: UIButton = {
        let button = UIButton()
        button.backgroundColor = UIColor(white: 0.95, alpha: 1.0)
        
        return button
    }()
    
    private lazy var retweetedLabel: FFLabel = FFLabel(title: "转发微博",
        titleColor: UIColor.darkGrayColor(),
        fontSize: 14,
        screenInset: WHYStatusCellMagrin)

}

// MARK: - 父类函数的重写
extension WHYStatusRetweetedCell {
    
    override func setupUI() {
        super.setupUI()
        
        contentView.insertSubview(backButton, belowSubview: pictureView)
        contentView.insertSubview(retweetedLabel, aboveSubview: backButton)
        
        backButton.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(contentLabel.snp_bottom).offset(WHYStatusCellMagrin)
            make.left.right.equalTo(contentView)
            make.bottom.equalTo(bottomView.snp_top)
        }
        
        retweetedLabel.snp_makeConstraints { (make) -> Void in
            make.left.top.equalTo(backButton).offset(WHYStatusCellMagrin)
        }
        
        pictureView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(retweetedLabel.snp_bottom).offset(WHYStatusCellMagrin)
            make.left.equalTo(contentView).offset(WHYStatusCellMagrin)
            make.size.equalTo(CGSize(width: 300, height: 90))
        }
        
        retweetedLabel.labelDelegate = self
        
    }
    
}
